package nero.yncc.com.createart.utils;

import android.app.Activity;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import cn.finalteam.galleryfinal.GalleryFinal;
import nero.yncc.com.createart.R;
import nero.yncc.com.createart.base.Constants;

/**
 * Created by nero on 2017/5/26.
 */

public class PopUtils {
    public static PopupWindow popupWindow=new PopupWindow();
    /**
     * @param isOne  是否单选
     *               @param num 多选张数  没有填写0
     * */
    public static void   showPhotoPopwindow(Context context, final boolean isOne, final int num, final GalleryFinal.OnHanlderResultCallback callback){
        View view= View.inflate(context, R.layout.pop_choose_photo,null);

         popupWindow=new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });

        TextView tv_take=(TextView)view.findViewById(R.id.tv_photo);
        TextView tv_camera=(TextView)view.findViewById(R.id.tv_takephoto);

        tv_take.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(isOne){
                    //单选
                    GalleryFinal.openGallerySingle(Constants.MOBILEGETPHOTO, callback);
                }else{
//                    多选
                    GalleryFinal.openGalleryMuti(Constants.MOBILEGETPHOTO,num, callback);
                }
                popupWindow.dismiss();
            }
        });

        tv_camera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
                GalleryFinal.openCamera(Constants.CAMERAGETPHOTO, callback);
            }
        });

       popupWindow.showAtLocation(((Activity)context).getWindow().getDecorView(), Gravity.CENTER,0,0);
    }
}
